---@class RedRob.SkillMgr
---@field New fun():RedRob.SkillMgr
local SkillMgr = RedRob.CreateClass("SkillMgr")
---@param actor RedRob.Player
function SkillMgr:OnCreate(actor)
    self.actor = actor
    ---@type RedRob.Skill[]
    self.equippedSkill = {} --装配的技能
    ---@type RedRob.Skill[]
    self.skillList = {}     --所有技能
    ---@type RedRob.Skill[]
    self.releaseList = {} --释放中的技能
    local cfg = dataTable.getDataTableByStringId("t_hero",self.actor:GetModelId())
    if not cfg then
        logError("找不到t_Hero"..modelId )
        return
    end
    if cfg.f_HeroAtk > 0 then
        self:EquipSkill(cfg.f_HeroAtk,RedRob.Config.SkillShowType.normalAttack)
    end
end
function SkillMgr:OnDestroy()
    self.actor = nil
    if self.skillList then
        for k,v in pairs(self.skillList) do
            v:OnDestroy()
        end
    end
    self.skillList = nil
end
function SkillMgr:EndSkill(skillId)
    local s = self.releaseList[skillId]
    self.releaseList[skillId] = nil
    if not s then return end
    s:EndSkill()
end
function SkillMgr:EndAllSkill(cleanEffect)
    for k,v in pairs(self.releaseList) do
        v:EndSkill(true)
        if cleanEffect then
            RedRob.EffectMgr.DestroyEffectBySkill(v.skillId)
        end
    end
    table.clear(self.releaseList)
end
function SkillMgr:EquipSkill(skillId,skillType)
    local s = self.equippedSkill[skillType]
    if s then return end
    local skill = self:CreateSkill(skillId)
    self.equippedSkill[skillType] = skill
end
function SkillMgr:CreateSkill(skillId,delay)
    local skill = RedRob.Skill.New()
    skill:OnCreate(self.actor,skillId,delay)
    self.skillList[skillId] = skill
    return skill
end
---@return RedRob.Skill
function SkillMgr:GetSkill(skillId)
    return self.skillList[skillId]
end
function SkillMgr:DoEquippedSkill(skillType)
    local s = self.equippedSkill[skillType]
    if not s then return end
    self:DoSkill(s.skillId)
end
function SkillMgr:GetEquippedSkill(skillType)
    return self.equippedSkill[skillType]
end
function SkillMgr:DoSkill(skillId)
    local s = self.skillList[skillId]
    if not s then return end
    local flag = s:DoSkill()
    if flag then
        self.releaseList[skillId] = s
    end
end
function SkillMgr:Update(dt)
    for k,v in pairs(self.releaseList) do
        v:Update(dt)
    end
end